<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>图书列表</title>
    <link href="css/layout.css" rel="stylesheet" type="text/css"/>
    <link href="css/list.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<table class="tablelist">
    <form action="AddServlet" method="post">
        <thead>
        <tr>
            <th><input type="checkbox" id="check"/>全选</th>
            <th>编号</th>
            <th>封面</th>
            <th>图书名称</th>
            <th>单价（元）</th>
            <th>状态</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${books}" var="book" varStatus="s">
            <c:set var="t" value="0"></c:set>
            <c:forEach items="${cart}" var="cart">
                <c:if test="${cart.id==book.id}">
                    <c:set var="t" value="1"></c:set>
                </c:if>
            </c:forEach>
            <tr>
                 
                <c:if test="${t==0}">
                    <td><input type="checkbox" name="checkbox" value="${book.id}"/></td>
                </c:if>
                
                <c:if test="${t!=0}">
                    <td></td>
                </c:if>
                <td>${s.count}</td>
                <td class="imgtd"><img src="${book.image}" height="110" width="78"/></td>
                <td>${book.name}</td>
                <td>${book.price}元/本</td>
                <td>
                        
                    <c:if test="${t==0}">未添加到购物车</c:if>
                        
                    <c:if test="${t!=0}"><font color="blue">已添加</font></c:if>
                </td>
            </tr>
        </c:forEach>

        </tbody>
        <thead>
        <tr>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th></th>
            <th><input type="submit" style="background-color:green" value="添加购物车"/></th>
        </tr>
        </thead>
    </form>
</table>
</body>

<script>
    document.getElementById("check").onclick = function () {
        var checked = document.getElementById("check").checked;
        var checkson = document.getElementsByName("checkbox");
        if (checked) {
            for (var i = 0; i < checkson.length; i++) {
                checkson[i].checked = true;
            }
        } else {
            for (var i = 0; i < checkson.length; i++) {
                checkson[i].checked = false;
            }
        }
    }
</script>
</html>

